<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\grid\GridView;
use backend\helpers\ActionButton;
use backend\helpers\FileViewHelper;
use backend\helpers\DateTimeHelper;
use backend\models\Project;
use kartik\export\ExportMenu;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model backend\models\Project */

$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Проекты', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

$this->params['id'] = $model->id;

\yii\web\YiiAsset::register($this);

?>
<div class="container project-view">

    <h1 class="main-title"><?= Html::encode($this->title) ?></h1>

    <div class="row">
        <div class="col-sm-11"><?= $this->render('/project/_menu') ?></div>
        <div class="col-sm-1"><?= ActionButton::delete($model->id, 'Вы точно хотите удалить информацию о проекте?', 'deleteProject') ?></div>
    </div>
    
</div>

<div class="container contract-table-container">
    <? if (\Yii::$app->user->can('createProjectSmi')): ?>    

    <div class="create-form furniture-type-form">

        <?php $form = ActiveForm::begin(); ?>

            <?= $form->field($modelSmi, 'title')->textInput(['maxlength' => true]) ?>
            <div class="row">
                <?= $form->field($modelSmi, 'source_name', ['options' => ['class' => 'col-sm-8']])->textInput(['maxlength' => true]) ?>
                <?= $form->field($modelSmi, 'date_published', ['options' => ['class' => 'col-sm-4']])->input('date') ?>
            </div>
            <?= $form->field($modelSmi, 'url')->textInput(['maxlength' => true]) ?>

            <div class="form-group">
                <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
            </div>

        <?php ActiveForm::end(); ?>

    </div>

    <br>
    <br>
    <? endif; ?>


    <?= ExportMenu::widget([
            'dataProvider' => $smiDataProvider,
            'columns' => [
                'title',
                'source_name',
                'url',
                [
                    'attribute' => 'date_published',
                    'format' => 'date',
                ],
            ],
            'exportConfig' => [
                ExportMenu::FORMAT_HTML => false,
                ExportMenu::FORMAT_CSV => false,
                ExportMenu::FORMAT_TEXT => false,
                ExportMenu::FORMAT_EXCEL => false,
            ]
        ]);
    ?>

    <?= GridView::widget([
        'dataProvider' => $smiDataProvider,
        'tableOptions' => [
            'class' => 'table table-striped'
        ],
        'layout' => '{items}', 
        'columns' => [
            [
                'attribute' => 'title',
                'contentOptions' => ['style' => 'width:35%; white-space: normal;'],
            ],
            'source_name',
            [
                'attribute' => 'url',
                'value' => function($model) {
                    return HTML::a(
                        \yii\helpers\StringHelper::truncate($model->url, 40, '...'), 
                        $model->url, 
                        ['target' => '_blank']
                    );
                },
                'format' => 'raw',
            ],
            'date_published:date',
            [
                'class' => 'yii\grid\ActionColumn',
                'controller' => 'project-smi',
                'visibleButtons' =>
                [
                    'view' => Yii::$app->user->can('browseProjectSmi'),
                    'update' => Yii::$app->user->can('updateProjectSmi'),
                    'delete' => Yii::$app->user->can('deleteProjectSmi'),
                ]
            ],
        ],
    ]);?>
</div>
